package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Message;
import cn.wolfcode.trip.base.query.MessageQueryObject;
import cn.wolfcode.trip.base.service.ICommentService;
import cn.wolfcode.trip.base.service.IMessageService;
import cn.wolfcode.trip.base.service.IMyDoGoodService;
import cn.wolfcode.trip.base.util.JSONResult;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 私信/聊天资源管理控制器
 * @author : bobo
 */
@RestController
@RequestMapping("/messages")
public class MessageController {
    @Autowired
    private IMessageService messageService;

    @Autowired
    private ICommentService commentService;

    @Autowired
    private IMyDoGoodService myDoGoodService;

    /**
     * 获取某一用户的聊天对象
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public List<Map> selectChartPerson(@PathVariable Long id){
        return messageService.selectChartPerson(id);
    }

    /**
     * 获取登录用户和聊天用户的聊天记录
     * @param qo
     * @return
     */
    @GetMapping("/{senderId}/{receiverId}/chart")
    public List<Message> selectChartMessages(MessageQueryObject qo){
        return messageService.selectChartMessages(qo);
    }

    /**
     * 保存及时聊天的数据
     * @param message
     * @return
     */
    @PostMapping()
    public List<Message> saveMessage(Message message){
        return messageService.saveMessage(message);
    }

    /**
     * 获取新的聊天数据
     * @param qo
     * @return
     */
    @PostMapping("/newMessages")
        public List<Message> selectNewChartMessages(MessageQueryObject qo){
        return messageService.selectNewChartMessages(qo);
    }

    /**
     * 查询当前用户之前最后一次点击私信到现在所接收到的所有私信总和
     * @return
     */
    @GetMapping("/{receiverId}/allCount")
    public int selectMessageCount(@PathVariable Long receiverId){
        return messageService.selectMessageCount(receiverId);
    }
    /**
     * 查询当前用户之前最后一次点击聊天到现在所接收到的每个人的私信数
     * @return
     */
    @GetMapping("/{receiverId}/oneCount")
    public List<Map> selectChartCount(@PathVariable Long receiverId){
        return messageService.selectChartCount(receiverId);
    }

    /**
     * 查询当前用户我的信息页面距离上次进入被评论的总和
     * @param id
     * @return
     */
    @GetMapping("/{id}/allComment")
    public int selectCommentCount(@PathVariable Long id){
        return commentService.selectCommentCount(id);
    }
    /**
     * 查询当前用户我的评论页面距离上次进入被评论的分类的id
     * @param id
     * @return
     */
    @GetMapping("/{id}/oneComment")
    public List<Map> selectOneCommentCount(@PathVariable Long id){
        return commentService.selectOneCommentCount(id);
    }

    /**
     * 查询该用户收到的未读点赞总数
     * @param id
     * @return
     */
    @GetMapping("/{id}/allDoGood")
    public int selectDoGoodCount(@PathVariable Long id){
       return myDoGoodService.selectDoGoodCount(id);
    }
}
